package com.demo.studentidcard.service;

import com.demo.studentidcard.dao.impl.AccountDaoImpl;
import com.demo.studentidcard.entity.Account;
import com.demo.studentidcard.entity.RecordsOfConsumption;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xuziao
 * @date 2021/9/24 12:34
 */
@Service
public class BaseService {
    final AccountDaoImpl accountDaoImpl;

    @Autowired
    public BaseService(AccountDaoImpl accountDaoImpl) {
        this.accountDaoImpl = accountDaoImpl;
    }

    public boolean resign(Account account) {
        return accountDaoImpl.addAccount(account);
    }

    public boolean recharge(String id, int money) {
        return accountDaoImpl.recharge(id, money);
    }

    public int getBalance(String id){
        return accountDaoImpl.getBalance(id);
    }

    public boolean setIsLost(String id) {
        return accountDaoImpl.setIsLost(id);
    }

    public boolean setIsLostNone(String id) {
        return accountDaoImpl.setIsLostNone(id);
    }

    public String getRecordsOfConsumption(String id) {
        int count = 0;
        StringBuilder record = new StringBuilder();
        List<RecordsOfConsumption> recordsOfConsumptions = accountDaoImpl.getRecordsOfConsumption(id);
        for (RecordsOfConsumption recordsOfConsumption : recordsOfConsumptions) {
            count++;
            record.append("第").append(count).append("条消费记录：");
            record.append(recordsOfConsumption.toString()).append("-----");
        }
        record.append("id是消费者id, count是消费的钱数, changeTime是消费时间");
        return  record.toString();
    }

}
